// pages/mine/mine.js
import { getLogin } from '../request/api'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        code: '',
        imgList: [],
        img: null
    },
    img() {
        wx.chooseImage({
            count: 1, //一次上传的数量
            sizeType: ['original', 'compressed'],
            sourceType: ['album', 'camera'], // album 从相册选图，camera 使用相机，默认二者都有
            success: res => {
                var tempFilePaths = res.tempFilePaths
                console.log(tempFilePaths)
                let arr = [...tempFilePaths, ...this.data.imgList]
                this.setData({
                    imgList: arr
                })
                wx.uploadFile({
                    url: 'https://www.liulongbin.top:8888/api/private/v1/upload',
                    filePath: tempFilePaths[0],
                    name: 'file',
                    header: {
                        "Content-Type": "multipart/form-data",
                        Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjUwMCwicmlkIjowLCJpYXQiOjE2Nzk0NjY0MzcsImV4cCI6MTY3OTU1MjgzN30.GbqCXvH0_WdbhLAYR4uokbPG3pOTOVgiVjEx9Xt28js",
                    },
                    success: res => console.log(res),
                    fail: err => console.log(err)
                })
            }
        })
    },
    login() {
        wx.login({
            success: res => {
                console.log(res);
                this.setData({
                    code: res.code
                })
            }
        })
        wx.getUserProfile({
            desc: 'desc',
            success: res1 => {
                console.log(res1,52);
                this.setData({
                    img:res1.userInfo.avatarUrl
                })
                wx.setStorageSync('img',res1.userInfo.avatarUrl)
                let obj = {
                    encryptedData: res1.encryptedData,
                    rawData: res1.rawData,
                    iv: res1.iv,
                    signature: res1.signature,
                    code: this.data.code
                }
                getLogin(obj).then(res => {
                    console.log(res);

                })
                wx.setStorageSync('token', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo')
            }
        })

    },
    back() {
   let token= wx.getStorageSync('token')
   wx.clearStorage(token)
       this.setData({
           cart:cart
       })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        let img = wx.getStorageSync('img')
        this.setData({
            img: img
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        let img = wx.getStorageSync('img')
        this.setData({
            img: img
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})